package com.fourth.service.impl;/**
 * Created by Administrator on 2019/6/29.
 */


import com.fourth.entity.Orders;
import com.fourth.service.OrdersService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 定时任务服务
 * @Author:debug (SteadyJack)
 * @Date: 2019/6/29 21:26
 **/
@Service
public class SchedulerService {

    private static final Logger log= LoggerFactory.getLogger(SchedulerService.class);

    @Autowired
    private OrdersService ordersService;

    @Autowired
    private Environment env;


    /**
     * 定时获取status=0的订单并判断是否超过TTL，然后进行失效
     */
    //@Scheduled(cron = "0/10 * * * * ?")
    @Scheduled(cron = "0 0/30 * * * ?")
    public void schedulerExpireOrders(){
        //log.info("v1的定时任务----");

        try {
            List<Orders> ordersList=ordersService.selectExpireOrders();
            if (ordersList!=null && !ordersList.isEmpty()){
                ordersList.stream().forEach(ol ->{
                    System.out.println("定时任务时间差："+ol.getDiffTime());
                    if(ol!=null && ol.getDiffTime()>31555){/*env.getProperty("scheduler.expire.orders.time",Integer.class)*/
                        System.out.println("判断时间是否设定时间");
                        ordersService.updateOrdersByoNo(ol.getONo());
                    }
                });

            }

        }catch (Exception e){
            log.error("定时获取status=0的订单并判断是否超过TTL(24)，然后进行失效-发生异常：",e.fillInStackTrace());
        }
    }

}




































